package com.idopartx.phonelightning.ui.adapter

import android.view.View
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.idopartx.phonelightning.R
import com.idopartx.phonelightning.entity.ScreenLightningEntity
import com.idopartx.phonelightning.utils.DensityUtil

class ScreenSelectAdapter(var onItemClick: (ScreenLightningEntity) -> Unit) :
    BaseQuickAdapter<ScreenLightningEntity, BaseViewHolder>(R.layout.adapter_select_screen) {

    override fun convert(holder: BaseViewHolder, item: ScreenLightningEntity) {

        holder.getView<ImageView>(R.id.iv_bg).apply {
            setImageResource(
                when (holder.adapterPosition) {
                    0 -> R.mipmap.icon_single_line
                    1 -> R.mipmap.icon_double_line
                    2 -> R.mipmap.icon_arround_circle
                    else -> R.mipmap.icon_arround_line
                }
            )
        }

        holder.itemView.setOnClickListener {
            data.forEach {
                it.isCheck = item.type == it.type
            }
            onItemClick(item)
            notifyDataSetChanged()
        }
//        holder.getView<ImageView>(R.id.iv_bg).apply {
//
//            val layoutParams = layoutParams as ConstraintLayout.LayoutParams
//
//            layoutParams.setMargins(
//                if (holder.adapterPosition == 0) {
//                    0
//                } else {
//                    DensityUtil.dip2px(context, 14f)
//                }, 0, 0, 0
//            )
//
//            this.layoutParams = layoutParams
//        }

        holder.getView<ImageView>(R.id.iv_check).apply {


            setImageResource(
                if (item.isCheck) {
                    R.mipmap.icon_public_checked
                } else {
                    R.mipmap.icon_type_unchecked
                }
            )
        }


    }
}